package com.own.component.util.time.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * TimetableConfig
 *
 * @author chenxueli
 * @date 2021/3/15 11:13
 */
@Getter
@NoArgsConstructor
public class TimetableConfig {

    /**
     * 默认维度
     */
    private Integer defaultVacant = 1;

    /**
     * 解析的格式
     */
    @Setter
    private DateTimeFormatter resolveFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
    /**
     * 导出的格式
     */
    @Setter
    private DateTimeFormatter exportFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");

    @Setter
    private String itemSplitContent = ";";
    @Setter
    private String timeSplitContent = "-";

    @Setter
    private boolean advance = false;

    @Setter
    @Schema(title = "小时")
    private Integer hour = 0;

    @Setter
    @Schema(title = "分钟")
    private Integer minute = 0;

    @Setter
    @Schema(title = "秒")
    private Integer second = 0;

    public TimetableConfig(int vacant) {
        defaultVacant = vacant;
        initAdvance();
    }

    public TimetableConfig initAdvance() {
        this.advance = false;
        this.hour = 0;
        this.minute = 0;
        this.second = 0;
        return this;
    }

    public TimetableConfig advance(LocalTime time) {
        if (time == null) {
            return initAdvance();
        } else {
            this.advance = true;
            this.hour = time.getHour();
            this.minute = time.getMinute();
            this.second = time.getSecond();
        }
        return this;
    }

    public TimetableConfig advance(Integer hour, Integer minute, Integer second) {
        this.advance = true;
        this.hour = getHour();
        this.minute = getMinute();
        this.second = getSecond();
        return this;
    }

}
